package com.i9he.ping.utils;

import static com.i9he.ping.utils.ConfigUtils.configuration;

import org.apache.commons.lang.StringUtils;

import com.i9he.ping.sms.TaobaoIpBreakSms;

public class SmsUtils {

	public static boolean sendBreakIp(String[] phoneNumbers, String[] iplist) {
		
		TaobaoIpBreakSms sms = new TaobaoIpBreakSms();
		sms.setAppKey(configuration.getString("taobao.sms.appKey"));
		sms.setSecret(configuration.getString("taobao.sms.secret"));
		sms.setSmsFreeSignName(configuration.getString("taobao.sms.smsFreeSignName"));
		sms.setSmsTemplateCode(configuration.getString("taobao.sms.smsTemplateCode"));
		sms.setSmsType(configuration.getString("taobao.sms.smsType"));
		sms.setUrl(configuration.getString("taobao.sms.url"));
		
		String ips = StringUtils.join(iplist, ",");
		ips = ips.replace('.', '-');
		boolean hasError = false;
		for (String recNum : phoneNumbers) {
			try {
				sms.send(recNum, ips);
			} catch (Exception e) {
				e.printStackTrace();
				hasError = true;
			}
		}
		return hasError;
	}
	
}
